﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using IFTRUE.DataCollection.DBUtility;//Please add references
namespace IFTRUE.DataCollection.DAL
{
	/// <summary>
	/// 数据访问类:commodity
	/// </summary>
	public partial class commodity
	{

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsEx(string code)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from data_commodity");
            strSql.Append(" where code=@code ");
            SqlParameter[] parameters = {
					new SqlParameter("@code", SqlDbType.VarChar,50)			};
            parameters[0].Value = code;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateEx(IFTRUE.DataCollection.Model.commodity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update data_commodity set ");
            strSql.Append("mall=@mall,");
            strSql.Append("commodityClass=@commodityClass,");
            strSql.Append("brands=@brands,");
            strSql.Append("name=@name,");
            strSql.Append("enName=@enName,");
            strSql.Append("title=@title,");
            strSql.Append("code=@code,");
            strSql.Append("url=@url,");
            strSql.Append("info=@info,");
            strSql.Append("price=@price,");
            strSql.Append("status=@status,");
            strSql.Append("createDate=@createDate,");
            strSql.Append("updateDate=@updateDate");
            strSql.Append(" where code=@code ");
            SqlParameter[] parameters = {
					new SqlParameter("@mall", SqlDbType.NVarChar,20),
					new SqlParameter("@commodityClass", SqlDbType.NVarChar,100),
					new SqlParameter("@brands", SqlDbType.NVarChar,20),
					new SqlParameter("@name", SqlDbType.NVarChar,20),
					new SqlParameter("@enName", SqlDbType.VarChar,20),
					new SqlParameter("@title", SqlDbType.NVarChar,50),
					new SqlParameter("@code", SqlDbType.VarChar,50),
					new SqlParameter("@url", SqlDbType.VarChar,200),
					new SqlParameter("@info", SqlDbType.VarChar),
					new SqlParameter("@price", SqlDbType.VarChar,15),
					new SqlParameter("@status", SqlDbType.NVarChar,10),
					new SqlParameter("@createDate", SqlDbType.DateTime),
					new SqlParameter("@updateDate", SqlDbType.DateTime),
					new SqlParameter("@guid", SqlDbType.Char,36)};
            parameters[0].Value = model.mall;
            parameters[1].Value = model.commodityClass;
            parameters[2].Value = model.brands;
            parameters[3].Value = model.name;
            parameters[4].Value = model.enName;
            parameters[5].Value = model.title;
            parameters[6].Value = model.code;
            parameters[7].Value = model.url;
            parameters[8].Value = model.info;
            parameters[9].Value = model.price;
            parameters[10].Value = model.status;
            parameters[11].Value = model.createDate;
            parameters[12].Value = model.updateDate;
            parameters[13].Value = model.guid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
	}
}

